package com.gorkr;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.junit.Test;

/**
 * @author 张心宇 <zhangxinyu20@kuaishou.com>
 * Created on 2022-12-20
 */
public class E448 {

    public List<Integer> findDisappearedNumbers(int[] nums) {
        int n = nums.length;
        HashSet<Integer> set = new HashSet<>();
        for (int i = 1; i <= n; i++) {
            set.add(i);
        }
        Arrays.stream(nums).forEach(
                set::remove
        );
        return new ArrayList<>(set);
    }

    public List<Integer> findDisappearedNumbers2(int[] nums) {
        int n = nums.length;
        ArrayList<Integer> res = new ArrayList<>();
        for (Integer num : nums) {
            num %= n;
            if(num == 0){
                num = n;
            }
            nums[num - 1] += n;
        }
        for (int i = 0; i < n; i++) {
            if (nums[i] <= n) {
                res.add(i+1);
            }
        }
        return res;
    }

    @Test
    public void test(){
        System.out.println(findDisappearedNumbers2(new int[] {4, 3, 2, 7, 8, 2, 3, 1}));

    }
}
